package com.otv.arriendo.dao;

import java.util.List;
import com.otv.model.Arriendo;
import org.hibernate.SessionFactory;



/**
 * Class ArriendoDAO.
 */
public class ArriendoDAO implements IArriendoDAO {
	
	/** El/la session factory. */
	private SessionFactory sessionFactory;

	/**
	 * Get Hibernate Session Factory.
	 *
	 * @return SessionFactory - Hibernate Session Factory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Set Hibernate Session Factory.
	 *
	 * @param sessionFactory un(a) nuevo(a) session factory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

	


	@Override
	public void addArriendo(Arriendo arriendo) {
		getSessionFactory().getCurrentSession().save(arriendo);
	}


	@Override
	public void updateArriendo(Arriendo arriendo) {
		getSessionFactory().getCurrentSession().update(arriendo);
	}


	@Override
	public void deleteArriendo(Arriendo arriendo) {
		getSessionFactory().getCurrentSession().delete(arriendo);
	}


	@Override
	public Arriendo getArriendoById(int id) {
		return (Arriendo) getSessionFactory().openSession().createQuery("from Arriendo where id=?").setParameter(0,id).list().get(0);
	}


	@Override
	public List<Arriendo> getArriendos() {
		return getSessionFactory().openSession().createQuery("from Arriendo").list();
	}

}
